package com.ForeHome.app.Controller;

import com.ForeHome.app.Service.ProductService;
import com.tamll.Type.DataType;
import com.tamll.bean.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ProductController {

    @Autowired
    private ProductService productService;


    @GetMapping("titleCategoryId")
    public DataType titleCategoryId(Integer categoryId){
        DataType dataType=new DataType();
        dataType.setProducts(productService.title_category_id(categoryId));
        return dataType;
    }


    /**
     *
     * @return
     */
    @GetMapping("selectListImage")
    public DataType selectListImage(){
        List<Product> products = productService.listImage();
        DataType dataType=new DataType();
        dataType.setProducts(products);
        return dataType;
    }


    /**
     * 根据商品id查询将商品信息存放在了集合的第一个位置
     * @param ProductId 商品id
     * @return DataType
     */
    @GetMapping("selectProductId")
    public DataType selectProductId(Integer ProductId){
        DataType dataType=new DataType();
        Product product = productService.selectProductId(ProductId);
        dataType.setProduct(product);
        return dataType;
    }


    @GetMapping("getProduct")
    public Product getProduct(Integer productId){
        return productService.selectProductId(productId);
    }

}
